﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
using ImmunityBuster;


namespace TappUp_Refresh
{
    public class Sprite 
    {
        public Vector2 Position;
        public Texture2D Texture;
        public Rectangle Bounds;
        public Vector2 Velocity;
        public Vector2 Accelaration;
        public bool CollisionFlag = false;
        public Animation animation;
        public double Weight;
        public double COG;
        public bool EnableParticlePhysics = false;
        public  List<Sprite> Collections;
        public bool flag;

        public Point CenterPosition;

        public Sprite()
        {
            Position = new Vector2();
            Bounds = new Rectangle();
            Velocity = new Vector2();
            Accelaration = new Vector2();
            animation = new Animation();
        }



        public void Initialize(String AssetName, ContentManager content)
        {
            Texture = content.Load<Texture2D>(AssetName);
        }

        public void Update(GameTimerEventArgs gameTime)
        {           
            Position.X += Velocity.X * (int)gameTime.ElapsedTime.TotalMilliseconds;
            Position.Y += Velocity.Y * (int)gameTime.ElapsedTime.TotalMilliseconds;
            Bounds = Texture.Bounds;
            Bounds.X = (int)Position.X;
            Bounds.Y = (int)Position.Y;

            if (animation != null)
            {
                animation.Position.X = Position.X;
                animation.Position.Y = Position.Y;
                animation.Update(gameTime);
            }

            CenterPosition = Bounds.Center;
//#if EnableParticlePhysics
            if(EnableParticlePhysics)
            foreach(Sprite sprite in Collections)
            {
                if (this.Position.X <= sprite.Position.X && this.Position.X >= sprite.Position.X + sprite.Texture.Bounds.Width)
                {
                    if (this.Position.Y > sprite.Position.Y)
                        continue;

                    if (this.Position.Y + this.Texture.Bounds.Height < sprite.Position.Y + 1 && this.Position.Y + this.Texture.Bounds.Height > sprite.Position.Y - 1)
                    {
                        this.Velocity.Y *= -1;
                    }
                    else
                        continue;
                }
                else
                    continue;
            }
//#endif
        }
    }
}
